<template>
  <div class="icons">
    <swiper :options="swiperOption">
      <swiper-slide class="swiper-container" v-for="(page,index) of pages" :key="index">
        <div class="icon" v-for="item of page" :key="item.id">
          <img class="icon-img" :src="item.imgUrl"/>
          <p class="icon-text">{{item.desc}}</p>
        </div>
      </swiper-slide>
    </swiper>
  </div>
</template>

<script>
export default {
  name:'HomeIcon',
  props: {
    list: Array
  },
  data () {
    return {
      swiperOption: {
        autoplay: false
      }
    }
  },
  computed: {
    pages () {
      const pages = []
      this.list.forEach((item,index) => {
        const page = Math.floor(index / 8)
        if (!pages[[page]]){
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    }
  }
}
</script>

<style lang="stylus" scoped>
  @import '~styles/varibles.styl'
  @import '~styles/mixins.styl'
  .icons >>> .swiper-container
    height: 0
    padding-bottom: 50%
  .icons
    margin-top: .1rem
    .icon
      // position: relative
      float: left
      width: 25%
      height: 0
      padding-bottom: 25%
      .icon-img
        display: block
        width: 65%
        margin: 0.12rem auto
      .icon-text
        text-align: center
        color: $darkTextColor
        padding: 0 0.22rem
        ellipsis()
</style>
